<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>登录</title>

  <link rel="stylesheet" href="../css/adminlte.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box" id="app">
  <!-- /.login-logo -->
  <div class="card card-outline card-primary">
    <div class="card-header text-center">
      <b>jiug</b>file
    </div>
    <div class="card-body">

        <div class="input-group mb-3">
          <input type="text" class="form-control" v-model="form.username" placeholder="用户名">
        </div>
        <div class="input-group mb-3">
          <input type="password" class="form-control" v-model="form.password" placeholder="密码">
        </div>
        <div class="row">
          <div class="col-12">
            <span @click="onSubmit()" class="btn btn-primary btn-block">登录</span>
          </div>
        </div>


    </div>
    <!-- /.card-body -->
  </div>
  <!-- /.card -->
</div>
<!-- /.login-box -->

<!-- vue -->
<script src="https://www.jiug.top/js/vue.min.js"></script>
<!-- axios -->
<script src="https://www.jiug.top/js/axios.min.js"></script>

<script>
    new Vue({
        el: '#app',
        data: {
            form: {
                username: '',
                password: ''
            }
        },
        methods: {
            onSubmit () {
                axios.post('/login', this.form, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then((res) => {
                    if(res.data.code==200){
                        document.location.href = '/to/index'
                    }else{
                        alert("用户名密码不正确！");
                    }
                }).catch((res) => {
                    console.log("提交失败")
                })
            }
        }
    })
</script>

</body>
</html>
